package com.neusoft.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neusoft.dao.RentDao;
import com.neusoft.entity.Pay;
import com.neusoft.dao.PayDao;
import com.neusoft.entity.Rent;
import com.neusoft.service.PayService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Pay)表服务实现类
 *
 * @author makejava
 * @since 2020-06-16 11:29:12
 */
@Service("payService")
public class PayServiceImpl implements PayService {
    @Resource
    private PayDao payDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Pay queryById(Integer id) {
        return this.payDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public IPage<Pay> queryAllByLimit(int offset, int limit, Pay bean) {
        Page<Pay> page = new Page<>(offset,limit);
//        QueryWrapper<Student> wrapper = new QueryWrapper<>();
//        wrapper.like("account",bean.getAccount())
//                .eq("mobile",bean.getMobile()).
//                gt("reg_date",bean.getStartTime()).
//                lt("reg_date",bean.getEndTime());
        page.setRecords(payDao.queryAll(page,bean));
        return page;
    }

    @Override
    public List<Pay> queryAll(Pay bean) {
        return null;
    }


    /**
     * 新增数据
     *
     * @param pay 实例对象
     * @return 实例对象
     */
    @Override
    public Pay insert(Pay pay) {
        this.payDao.insert(pay);
        return pay;
    }

    /**
     * 修改数据
     *
     * @param pay 实例对象
     * @return 实例对象
     */
    @Override
    public int update(Pay pay) {
        return this.payDao.update(pay);
    }

    @Override
    public boolean deleteById(List<Integer> ids) {
        System.out.println("执行批量删除");
        if(ids == null || ids.size()==0){
            return false;
        }
        StringBuffer sb = new StringBuffer("id in (");
        for(Integer item:ids){
            sb.append("'");
            sb.append(item);
            sb.append("',");
        }
        sb.deleteCharAt(sb.lastIndexOf(","));
        sb.append(")");
        return this.payDao.delete("stu.pay",sb.toString())>0;
    }

    @Override
    public boolean deleteById1(Integer id) {
        System.out.println("删除单挑数据");
        if(id == null){
            return false;
        }
        StringBuffer sb = new StringBuffer("id =");
        sb.append(id);
        System.out.println(sb.toString());
        return this.payDao.delete1("stu.pay",sb.toString())>0;
    }
}